package leecode

import (
	"container/list"
)

type MyHashSet struct {
	hashList *list.List
}

func Constructor705() MyHashSet {
	hashList := list.New()
	return MyHashSet{hashList: hashList}
}

func (this *MyHashSet) Add(key int) {
	if !this.Contains(key) {
		this.hashList.PushBack(key)
	}
}

func (this *MyHashSet) Remove(key int) {
	//删除指定元素
	for e := this.hashList.Front(); e != nil; e = e.Next() {
		if e.Value.(int) == key {
			// Remove the element from the list
			this.hashList.Remove(e)
			return
		}
	}
}

func (this *MyHashSet) Contains(key int) bool {
	//通过删除一个元素的返回值来判断是否包含此元素
	for i := this.hashList.Front(); i != nil; i = i.Next() {
		if i.Value == key {
			return true
		}
	}
	return false
}
